import { game, Game, Label, Node, SpriteFrame, sys, Toggle } from "cc"
import { ccclass, BaseUI, EUILayer, EBlockOnceAdType, EPlatformType, EBottomAdType, _config_, _privacy, SwitchSpriteCC, _platform, _ui, _guide, _audio, _gameType, SwitchChildrenCC, _prop } from "../../main/script/Main"
import { CGameData, initData } from "../../app/GameDefine"
import { ILevelSelectUIData } from "../../scene/script/ui/LevelSelectUI"
import { EPropId } from "../../main/script/module/define/LogicDefine"


@ccclass("TTSidebarUI")
export class TTSidebarUI extends BaseUI {
	public layerType = EUILayer.Panel
	public blockOnceAdType = EBlockOnceAdType.Show

	private cSwitchChildrenCC_btn: SwitchChildrenCC = null!


	protected onCreate(): void {
		switch (_platform.type) {
			case EPlatformType.wx:
				this.bottomAdType = EBottomAdType.Native
				break;
			default:
				this.bottomAdType = EBottomAdType.Banner
				break;
		}
		this.addEvent(_platform._tt.sidebar.EventType.REWARD_CHANGE, this.updateView, this, _platform)
	}

	protected onOpen() {
		this.updateView()

	}

	private updateView() {
		if (_platform._tt.sidebar.isReward) {
			this.cSwitchChildrenCC_btn.index = 0
		}
		else {
			if (_platform._tt.sidebar.checkReward()) {
				this.cSwitchChildrenCC_btn.index = 1
			}
			else {
				this.cSwitchChildrenCC_btn.index = 2
			}
		}
	}

	private onClickReward() {
		_platform._tt.sidebar.reward()
		this.updateView()

		_prop.addProp(EPropId.tip)
		_ui.tip("领取成功！提示道具+1")
	}

	private onClickTo() {
		_platform._tt.sidebar.to()
	}

}
